home *** CD-ROM | disk | FTP | other *** search
- #ifndef __NUMERAL_CC
- #define __NUMERAL_CC
- #pragma option push -b -a4 -Vx- -Ve- -w-inl -w-aus -w-sig
-
- /***************************************************************************
- *
- * numeral.cc - Definitions for the Standard Library numeric facets
- *
- *
- ***************************************************************************
- *
- * (c) Copyright 1994, 1995 Rogue Wave Software, Inc.
- * ALL RIGHTS RESERVED *
- * The software and information contained herein are proprietary to, and
- * comprise valuable trade secrets of, Rogue Wave Software, Inc., which
- * intends to preserve as trade secrets such software and information.
- * This software is furnished pursuant to a written license agreement and
- * may be used, copied, transmitted, and stored only in accordance with
- * the terms of such license and with the inclusion of the above copyright
- * notice. This software and information or any other copies thereof may
- * not be provided or otherwise made available to any other person.
- *
- * Notwithstanding any other lease or license that may pertain to, or
- * accompany the delivery of, this computer software and information, the
- * rights of the Government regarding its use, reproduction and disclosure
- * are as set forth in Section 52.227-19 of the FARS Computer
- * Software-Restricted Rights clause.
- *
- * Use, duplication, or disclosure by the Government is subject to
- * restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
- * Technical Data and Computer Software clause at DFARS 252.227-7013.
- * Contractor/Manufacturer is Rogue Wave Software, Inc.,
- * P.O. Box 2328, Corvallis, Oregon 97339.
- *
- * This computer software and information is distributed with "restricted
- * rights." Use, duplication or disclosure is subject to restrictions as
- * set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
- * Computer Software-Restricted Rights (April 1985)." If the Clause at
- * 18-52.227-74 "Rights in Data General" is specified in the contract,
- * then the "Alternate III" clause applies.
- *
- **************************************************************************/
-
- #ifndef __STD_RW_LOCNUMRW__
- #include <rw/numbrw>
- #endif
-
- #ifndef _RWSTD_NO_NAMESPACE
- namespace __rwstd {
- #endif
-
- // -----------------------------------------------
- // Template numpunct_data<charT> member functions.
- // -----------------------------------------------
-
- template <class charT>
- void numpunct_data<charT>::rw_init (void) {
- tf_defs_[0].s=tn_.c_str();
- tf_defs_[0].v=1;
- tf_defs_[1].s=fn_.c_str();
- tf_defs_[1].v=0;
-
- tf_map_.num_defs_=2 ;
- tf_map_.defs_=tf_defs_;
- }
-
- template <class charT>
- numpunct_init<charT>*
- _RWSTDExport fixup_numpunct_init
- (numpunct_init<char> *init,charT*)
- {
- if (init->del_)
- delete[] (char*) init;
- return NULL;
- }
-
- template <class charT>
- numpunct_init<charT>*
- numpunct_data<charT>::get_init_by_name_
- (const char *name)
- {
- return fixup_numpunct_init(get_named_init_(name),(charT*)0);
- }
-
-
- #ifndef _RWSTD_NO_NAMESPACE
- } namespace std {
- #endif
-
-
-
- // ----------------------------------------------------
- // Facet num_get<charT,InputIterator> member templates.
- // ----------------------------------------------------
-
-
- template <class charT, class InputIterator>
- locale::id num_get<charT, InputIterator>::id;
-
- template <class charT, class InputIterator>
- num_get<charT,InputIterator>::~num_get() { }
-
- #ifndef _RWSTD_NO_BOOL
-
- template <class charT, class InputIterator>
- InputIterator num_get<charT,InputIterator>::do_get
- (InputIterator in, InputIterator end, ios_base& io,
- ios_base::iostate& err, bool& value) const
- {
- __RWSTD::digit_reader<charT,InputIterator> reader(in,end,io);
- long v=reader.to_ulong(reader.get_int_digits());
- err=ios_base::goodbit; // aka 0
-
- if (!reader.error)
- if (v==0)
- value=false;
- else if (v==1 && !reader.negative)
- value=true;
- else
- err=ios_base::failbit;
- else if (reader.advanced)
- err=ios_base::failbit;
- else {
- const numpunct<charT>& nump =
- _RWSTD_STATIC_CAST(const numpunct<charT>&,reader.punct);
- int k=reader.get_keyword(reader.get_tf_map(nump));
- if (k<0)
- err=ios_base::failbit;
- else
- value=k;
- }
-
- if (reader.reached_end)
- err|=ios_base::eofbit;
-
- return in;
- }
-
- #endif // _RWSTD_NO_BOOL
-
- template <class charT, class InputIterator>
- InputIterator num_get<charT,InputIterator>::do_get
- (InputIterator in, InputIterator end, ios_base& io,
- ios_base::iostate& err, void*& value) const
- {
- __RWSTD::digit_reader<charT,InputIterator> reader(in,end,io);
- void *v=reader.to_pointer(reader.get_pointer_digits());
- err=ios_base::goodbit;
-
- if (reader.error)
- err=ios_base::failbit;
- else
- value=v;
-
- if (reader.reached_end)
- err|=ios_base::eofbit;
-
- return in;
- }
-
- template <class charT, class InputIterator>
- InputIterator num_get<charT,InputIterator>::do_get
- (InputIterator in, InputIterator end, ios_base& io,
- ios_base::iostate& err, long& value) const
- {
- __RWSTD::digit_reader<charT,InputIterator> reader(in,end,io);
- long v=reader.to_ulong(reader.get_int_digits());
- err=ios_base::goodbit;
-
- if (!reader.error)
- if (reader.negative) {
- if ((v=-v)>0)
- reader.error=reader.overflow;
- } else
- if (v<0 && reader.radix==10)
- reader.error=reader.overflow;
-
- if (reader.error)
- err=ios_base::failbit;
- else
- value=v;
-
- if (reader.reached_end)
- err|=ios_base::eofbit;
-
- return in;
- }
-
- #ifdef _RWSTD_LONG_LONG
-
- template <class charT, class InputIterator>
- InputIterator num_get<charT,InputIterator>::do_get
- (InputIterator in, InputIterator end, ios_base& io,
- ios_base::iostate& err, _RWSTD_LONG_LONG& value) const
- {
- __RWSTD::digit_reader<charT,InputIterator> reader(in,end,io);
- _RWSTD_LONG_LONG v=reader.to_ulong_ulong(reader.get_int_digits());
- err=ios_base::goodbit;
-
- if (!reader.error)
- if (reader.negative) {
- if ((v=-v)>0)
- reader.error=reader.overflow;
- } else
- if (v<0 && reader.radix==10)
- reader.error=reader.overflow;
-
- if (reader.error)
- err=ios_base::failbit;
- else
- value=v;
-
- if (reader.reached_end)
- err|=ios_base::eofbit;
-
- return in;
- }
-
- #endif // _RWSTD_LONG_LONG
-
- template <class charT, class InputIterator>
- InputIterator num_get<charT,InputIterator>::do_get
- (InputIterator in, InputIterator end, ios_base& io,
- ios_base::iostate& err, unsigned short& value) const
- {
- __RWSTD::digit_reader<charT,InputIterator> reader(in,end,io);
- unsigned long v=reader.to_ulong(reader.get_int_digits());
- err=ios_base::goodbit;
-
- if (reader.error
- || v > (unsigned long) numeric_limits<unsigned short>::max()
- || (reader.negative && v!=0))
- err=ios_base::failbit;
- else
- value=v;
-
- if (reader.reached_end)
- err|=ios_base::eofbit;
-
- return in;
- }
-
- template <class charT, class InputIterator>
- InputIterator num_get<charT,InputIterator>::do_get
- (InputIterator in, InputIterator end, ios_base& io,
- ios_base::iostate& err, unsigned int& value) const
- {
- __RWSTD::digit_reader<charT,InputIterator> reader(in,end,io);
- unsigned long v=reader.to_ulong(reader.get_int_digits());
- err=ios_base::goodbit;
-
- if (reader.error
- || v > (unsigned long) numeric_limits<unsigned int>::max()
- || (reader.negative && v!=0))
- err=ios_base::failbit;
- else
- value=v;
-
- if (reader.reached_end)
- err|=ios_base::eofbit;
-
- return in;
- }
-
- template <class charT, class InputIterator>
- InputIterator num_get<charT,InputIterator>::do_get
- (InputIterator in, InputIterator end, ios_base& io,
- ios_base::iostate& err, unsigned long& value) const
- {
- __RWSTD::digit_reader<charT,InputIterator> reader(in,end,io);
- unsigned long v=reader.to_ulong(reader.get_int_digits());
- err=ios_base::goodbit;
-
- if (reader.error || (reader.negative && v!=0))
- err=ios_base::failbit;
- else
- value=v;
-
- if (reader.reached_end)
- err|=ios_base::eofbit;
-
- return in;
- }
-
- template <class charT, class InputIterator>
- InputIterator num_get<charT,InputIterator>::do_get
- (InputIterator in, InputIterator end, ios_base& io,
- ios_base::iostate& err, float& value) const
- {
- __RWSTD::digit_reader<charT,InputIterator> reader(in,end,io);
- float v=reader.to_float(reader.get_float_digits());
- err=ios_base::goodbit;
-
- if (reader.error)
- err=ios_base::failbit;
- else
- value=v;
-
- if (reader.reached_end)
- err|=ios_base::eofbit;
-
- return in;
- }
-
- template <class charT, class InputIterator>
- InputIterator num_get<charT,InputIterator>::do_get
- (InputIterator in, InputIterator end, ios_base& io,
- ios_base::iostate& err, double& value) const
- {
- __RWSTD::digit_reader<charT,InputIterator> reader(in,end,io);
- double v=reader.to_double(reader.get_float_digits());
- err=ios_base::goodbit;
-
- if (reader.error)
- err=ios_base::failbit;
- else
- value=v;
-
- if (reader.reached_end)
- err|=ios_base::eofbit;
-
- return in;
- }
-
- template <class charT, class InputIterator>
- InputIterator num_get<charT,InputIterator>::do_get
- (InputIterator in, InputIterator end, ios_base& io,
- ios_base::iostate& err, long double& value) const
- {
- __RWSTD::digit_reader<charT,InputIterator> reader(in,end,io);
- long double v=reader.to_long_double(reader.get_float_digits());
- err=ios_base::goodbit;
-
- if (reader.error)
- err=ios_base::failbit;
- else
- value=v;
-
- if (reader.reached_end)
- err|=ios_base::eofbit;
-
- return in;
- }
-
- // -----------------------------------------------------
- // Facet num_put<charT,OutputIterator> member templates.
- // -----------------------------------------------------
-
- template <class charT, class OutputIterator>
- locale::id num_put<charT, OutputIterator>::id;
-
- template <class charT, class OutputIterator>
- num_put<charT,OutputIterator>::~num_put() { }
-
- #ifndef _RWSTD_NO_BOOL
-
- template <class charT, class OutputIterator>
- OutputIterator num_put<charT,OutputIterator>::do_put
- (OutputIterator out, ios_base& io, charT fill, bool value) const
- {
- __RWSTD::digit_writer<charT,OutputIterator> writer(out,io);
- if (io.flags() & ios_base::boolalpha) {
- const numpunct<charT>& nump =
- _RWSTD_STATIC_CAST(const numpunct<charT>&,writer.punct);
- writer.put_keyword(writer.get_tf_string(nump,value),fill);
- } else {
- writer.digitize((unsigned long) (value? 1 : 0));
- writer.put_digits(fill);
- }
- return out;
- }
-
- #endif // _RWSTD_NO_BOOL
-
- template <class charT, class OutputIterator>
- OutputIterator num_put<charT,OutputIterator>::do_put
- (OutputIterator out, ios_base& io, charT fill, void* value) const
- {
- __RWSTD::digit_writer<charT,OutputIterator> writer(out,io);
- writer.digitize(value);
- writer.put_digits(fill);
- return out;
- }
-
- template <class charT, class OutputIterator>
- OutputIterator num_put<charT,OutputIterator>::do_put
- (OutputIterator out, ios_base& io, charT fill, long value) const
- {
- __RWSTD::digit_writer<charT,OutputIterator> writer(out,io);
- writer.digitize(value);
- writer.put_digits(fill);
- return out;
- }
-
- template <class charT, class OutputIterator>
- OutputIterator num_put<charT,OutputIterator>::do_put
- (OutputIterator out, ios_base& io, charT fill, unsigned long value) const
- {
- __RWSTD::digit_writer<charT,OutputIterator> writer(out,io);
- writer.digitize(value);
- writer.put_digits(fill);
- return out;
- }
-
- #ifdef _RWSTD_LONG_LONG
-
- template <class charT, class OutputIterator>
- OutputIterator num_put<charT,OutputIterator>::do_put
- (OutputIterator out, ios_base& io, charT fill, _RWSTD_LONG_LONG val) const
- {
- __RWSTD::digit_writer<charT,OutputIterator> writer(out,io);
- writer.digitize(val);
- writer.put_digits(fill);
- return out;
- }
-
- #endif // _RWSTD_LONG_LONG
-
- template <class charT, class OutputIterator>
- OutputIterator num_put<charT,OutputIterator>::do_put
- (OutputIterator out, ios_base& io, charT fill, double value) const
- {
- __RWSTD::digit_writer<charT,OutputIterator> digits(out,io);
- digits.digitize(value);
- digits.put_digits(fill);
- return out;
- }
-
- #ifndef _RWSTD_NO_LONG_DOUBLE
- template <class charT, class OutputIterator>
- OutputIterator num_put<charT,OutputIterator>::do_put
- (OutputIterator out, ios_base& io, charT fill, long double value) const
- {
- __RWSTD::digit_writer<charT,OutputIterator> digits(out,io);
- digits.digitize(value);
- digits.put_digits(fill);
- return out;
- }
- #endif // _RWSTD_NO_LONG_DOUBLE
-
- template <class charT, class OutputIterator>
- OutputIterator num_put<charT,OutputIterator>::do_put
- (OutputIterator out, ios_base& io, charT fill, short value) const
- {
- __RWSTD::digit_writer<charT,OutputIterator> writer(out,io);
- writer.digitize(value);
- writer.put_digits(fill);
- return out;
- }
-
- template <class charT, class OutputIterator>
- OutputIterator num_put<charT,OutputIterator>::do_put
- (OutputIterator out, ios_base& io, charT fill, unsigned short value) const
- {
- __RWSTD::digit_writer<charT,OutputIterator> writer(out,io);
- writer.digitize(value);
- writer.put_digits(fill);
- return out;
- }
-
- template <class charT, class OutputIterator>
- OutputIterator num_put<charT,OutputIterator>::do_put
- (OutputIterator out, ios_base& io, charT fill, int value) const
- {
- __RWSTD::digit_writer<charT,OutputIterator> writer(out,io);
- writer.digitize(value);
- writer.put_digits(fill);
- return out;
- }
-
- template <class charT, class OutputIterator>
- OutputIterator num_put<charT,OutputIterator>::do_put
- (OutputIterator out, ios_base& io, charT fill, unsigned int value) const
- {
- __RWSTD::digit_writer<charT,OutputIterator> writer(out,io);
- writer.digitize(value);
- writer.put_digits(fill);
- return out;
- }
-
- // ---------------------------------------
- // Facet numpunct<charT> member templates.
- // ---------------------------------------
-
- template <class charT>
- locale::id numpunct<charT>::id;
-
- template <class charT>
- numpunct<charT>::~numpunct() { }
-
- template <class charT>
- charT numpunct<charT>::do_decimal_point () const { return this->dp_; }
-
- template <class charT>
- charT numpunct<charT>::do_thousands_sep () const { return this->ts_; }
-
- template <class charT>
- string numpunct<charT>::do_grouping () const { return this->gr_; }
-
- template <class charT>
- _TYPENAME numpunct<charT>::string_type
- numpunct<charT>::do_falsename () const { return this->fn_; }
-
- template <class charT>
- _TYPENAME numpunct<charT>::string_type
- numpunct<charT>::do_truename () const { return this->tn_; }
-
- template <class charT>
- void numpunct<charT>::rw_init () {
- this->dp_=do_decimal_point();
- this->ts_=do_thousands_sep();
- this->gr_=do_grouping();
- this->fn_=do_falsename();
- this->tn_=do_truename();
-
- #ifndef _RWSTD_NO_NAMESPACE
- __rwstd::numpunct_impl<charT>::rw_init();
- #else
- numpunct_impl<charT>::rw_init();
- #endif
- }
-
- // ----------------------------------------------------------------------
- // Numeric punctuation by-name member templates: numpunct_byname<charT>
- // ----------------------------------------------------------------------
-
- template <class charT>
- numpunct_byname<charT>::numpunct_byname (const char *n, size_t refs):
- numpunct<charT>(refs,get_init_by_name_(n))
- { }
-
- template <class charT>
- numpunct_byname<charT>::~numpunct_byname()
- { }
-
- #ifndef _RWSTD_NO_NAMESPACE
- }
- #endif
-
- #pragma option pop
- #endif /* __NUMERAL_CC */
-